#ifndef __SWEI_WRAPPER_H
#define __SWEI_WRAPPER_H

#include <time.h>

#include "public/errno.h"
#ifndef ENODEV 
#define ENODEV  (19)
#endif

#include "service/include/swei_common.h"

#ifdef __cplusplus
extern "C" {
#endif


void swei_gen_workid(void);
uint32_t swei_get_workid(void);

/********************** TIME API ****************************/
uint32_t  swei_get_device_timestamp(void);
uint32_t swei_getsec(void);
uint32_t swei_getms(void);
bool    swei_timeout_sec(uint32_t start_time, uint32_t timeout);
bool    swei_timeout_ms(uint32_t start_time, uint32_t timeout);


/********************** TIME API END ****************************/


/********************** HEAP API ****************************/
#if 0
#include "cmsis_os2.h"
#define swei_malloc(size)     pvPortMalloc(size)
#define swei_free(ptr)        vPortFree(ptr)
#else
#include "global.h"
#define swei_malloc(size)     qlmalloc(size)
#define swei_free(ptr)        qlfree(ptr)
#endif
/********************** HEAP API END ****************************/


/********************** SOCKET API ****************************/
#include "modem/qlmodem/task_modem.h"
#include "service/include/swei_cert.h"
/* remap local socket type to modem socket type */
#define SWEI_TCP SOCKET_TCP     /* TCP */
#define SWEI_UDP SOCKET_UDP     /* UDP */
#define SWEI_SSL SOCKET_SSL     /* SSL */

/* wrapper api for module swei service*/
void    swei_network_reconnect(void);
void    swei_socket_enstablish_hook(void);
void    swei_socket_distablish_hook(void);
int32_t swei_socket_open(int32_t type, const char *ip, unsigned short port, 
                                            unsigned short local, int32_t mode);
int32_t swei_socket_close(int32_t socket_id);
ssize_t swei_socket_write(int32_t socket_id, const void *buf, size_t cnt);
ssize_t swei_socket_write_timeout(int32_t socket_id, const void *buf, size_t cnt, uint32_t timeout);
int32_t swei_socket_write_query(int32_t socket_id);
ssize_t swei_socket_read(int32_t socket_id, void *buf, size_t cnt);
void swei_socket_host_get(char *iphost, uint16_t max_iphost_len, uint16_t *port, uint8_t *is_ssl);
void swei_socket_cert_get(ssl_cert_t *ssl_data_ptr);
/***************************************************************/

/********************** FS/FLASH API ***************************/
int32_t     swei_file_upload(const char *name, uint8_t *buf, uint32_t len);
/***************************************************************/

/********************** NETWORK API ****************************/
/**
 * @brief 网络状态查询接口
 * @return 0/false 网络未连接
 * @return 1/true  网络已连接
 */
int32_t swei_network_is_ready(void);

/// @brief 网络重连接口
/// @param  
void swei_network_reconnect(void);
/***************************************************************/


/**********************  SYSTEM API ****************************/
// void swei_system_state_get(int8_t *power_state, int8_t *active_state);
int32_t swei_system_restore(uint32_t delay_reboot_ms);
int32_t swei_system_reboot(uint32_t delay_reboot_ms);
/***************************************************************/
#ifdef __cplusplus
}
#endif
#endif // __SWEI_WRAPPER_H